package inPutStreamAndoutPutStream;

import java.io.File;

public class DeleteDir {
    public static void main(String[] args) {
        try {
            File file=new File("abc");
            boolean delete = delete(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private static boolean delete(File file) throws FileNotFoundException {
        if (!file.exists()){
            throw new FileNotFoundException();
        }
        if (file.isFile()) return file.delete();

        File[] files = file.listFiles();
        for (File f : files) {
            delete(f);
        }

        return file.delete();
    }

    private static class FileNotFoundException extends Exception{
        public FileNotFoundException() {
            super("文件未找到");
        }
    }
}
